<script>
	import {
		getByMapsList
	} from './api/messages.js'
	import {
		login,
		wxMiniAuto
	} from './api/oauth.js'
	export default {
		onLaunch: function(op) {
			uni.getLocation({
				success: function(e) {
					console.log(e)
					/* 	latitude: 41.16763
						longitude: 80.26338 */
					var l = e.latitude + "," + e.longitude;
					uni.setStorageSync("location", l)
				}
			})
			var the = this;
			this.$loadLanguageMessages()
			console.log(uni.$u.config)



			// #ifdef MP-WEIXIN

			// #endif
			this.autoLogin()
			console.log(op)
			uni.setStorageSync("align", this.$t("align"))
			var scane = op.scane;
			console.log("LLLLLLLLLLLLLLLLLLLLLLLL", scane)
			var query = op.query;
			if (query.type == 0 || query.type == 4) {

				console.log("LLLLLLLLLLLLLLLLLLLLLLLL", query)
				uni.setStorageSync("parentUserId", query.userId)
			}
			//http://www.ukij.org/fonts/fonts/UKIJBom.ttf
			// #ifdef H5
			console.log("LLLLLLLLLLLLLLLLLLLLLLLL")
			//login()
			// #endif

			uni.loadFontFace({
				family: 'UICTFontTextStyleBody',
				source: 'url("http://www.ukij.org/fonts/fonts/UKIJBom.ttf")',
				success() {
					console.log('UICTFontTextStyleBody success')
				}
			})
			uni.$on('loginValid', function() {
				console.log("loginValid1")
				the.autoLogin()
			})
		},
		onShow: function() {
			console.log("onShow0000000")
		},
		onLoad() {
			console.log("onLoad0000000")
		},
		onHide: function() {

		},
		updated() {
			console.log("updated0000000")
		},
		methods: {
			autoLogin: function() {
				console.log("AutoLogin")
				if (!uni.getStorageSync("Authorization")) {
					// #ifdef MP-WEIXIN
					uni.login({
						provider: 'weixin',
						success: function(loginRes) {
							var code = loginRes.code;
							///	param['code'] = code
							//	console.log(param);
							var a = wxMiniAuto(code)
							a.then(res => {
									uni.removeStorageSync("parentUserId")
									uni.removeStorageSync("newUser")
									uni.setStorageSync("userInfo", res)


									if (res['mpSubscribe'] == undefined) {
										res['mpSubscribe'] = 0;
									}
									if (res.mpSubscribe == 0) {
										uni.$emit('userUpdateError')
										uni.navigateTo({
											url: "/pages/index/webview"
										})
									} else {

										uni.setStorageSync("Authorization", res
											.token)
										uni.$emit('userUpdate', res)
									}

								})
								.catch(e => {
									console.log("KKKKKKKKKKKKKKKKKKKKKKKKKKKK02", e)
									uni.$emit('userUpdateError')
								})
						},
						fail() {
							uni.$emit('userUpdateError')
						}
					})

					// #endif
					//  #ifdef H5
					login().then(res => {
							uni.removeStorageSync("parentUserId")
							uni.setStorageSync("userInfo", res)
							uni.setStorageSync("Authorization", res
								.token)
							uni.$emit('userUpdate', res)

						})
						.catch(e => {
							console.log("KKKKKKKKKKKKKKKKKKKKKKKKKKKK02", e)
							uni.$emit('userUpdateError')
						})
					// #endif

				} else {
					uni.$emit('userUpdateError')
				}
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
</style>